package com.qztech.sdk.model;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import android.content.Context;

import com.qztech.sdk.model.dao.DelayDao;
import com.qztech.sdk.model.dao.EqChannelDao;
import com.qztech.sdk.model.dao.EqSettingDao;
import com.qztech.sdk.model.dao.SummingDao;
import com.qztech.sdk.model.dao.UserProfileDao;
import com.qztech.sdk.model.dao.XoverDao;
import com.qztech.sdk.model.entities.DelayChannel;
import com.qztech.sdk.model.entities.EqChannel;
import com.qztech.sdk.model.entities.EqSetting;
import com.qztech.sdk.model.entities.SummingChannel;
import com.qztech.sdk.model.entities.SummingSetting;
import com.qztech.sdk.model.entities.UserProfile;
import com.qztech.sdk.model.entities.XoverChannel;
import com.qztech.sdk.model.entities.XoverSetting;

/**
 * @author:zhanghb
 * @date:2019/1/27
 * @email:2573475062@qq.com
 **/
@Database(
        entities = {
                UserProfile.class,
                EqSetting.class,
                EqChannel.class,
                SummingSetting.class,
                SummingChannel.class,
                XoverSetting.class,
                XoverChannel.class,
                DelayChannel.class
        },
        version = 7,
        exportSchema = false
)
public abstract class DspDatabase extends RoomDatabase {
    private final static String DB_NAME = "dsp_db";

    private volatile static DspDatabase INSTANCE;

    public abstract UserProfileDao userProfileDao();

    public abstract EqSettingDao eqSettingDao();

    public abstract EqChannelDao eqChannelDao();

    public abstract SummingDao summingDao();

    public abstract XoverDao xoverDao();

    public abstract DelayDao delayDao();

    public static DspDatabase getInstance(Context context) {
        if (INSTANCE == null) {
            synchronized (DspDatabase.class) {
                if (INSTANCE == null) {
                    INSTANCE = Room.databaseBuilder(context.getApplicationContext(), DspDatabase.class, DB_NAME)
                            .fallbackToDestructiveMigration()
                            .build();
                }
            }
        }
        return INSTANCE;
    }

}
